#include<bits/stdc++.h>
using namespace std;
int n;
int x[2005];
int col[2005];
int dfs(int now){
    if(now==n+1){
        int b=0,r=0,summ=0;
        for(int i=1;i<=n;i++){
            if(col[i]){
                if(x[i]==r)summ+=x[i];
                r=x[i];
            }
            else{
                if(x[i]==b)summ+=x[i];
                b=x[i];
            }
        }
        return summ;
    }
    col[now]=0;
    int ans=dfs(now+1);
    col[now]=1;
    ans=max(ans,dfs(now+1));
    return ans;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%d",&x[i]);
        if(n<=15){
            printf("%d\n",dfs(1));
            continue;
        }
    }
    return 0;
}